<?php
/**
 * Description of _note
 * 
 * @author trongkhoi
 * @since Dec 13, 2013 - 5:46:28 PM
 */
?>
<div class="box span12">
    <div class="box-header">
        <h2>
            <i class="icon-envelope"></i>
            Package
        </h2>
    </div>
    <div class="box-content">        
        <link type="text/css" rel="stylesheet" href="<?php echo $this->assetDirWeb ?>css/Webmaster/crud.css" />
        <div class="row-fluid">
            <div id="list_item" class="span12">
                <?php if (Yii::app()->user->hasFlash('success')): ?>
                    <div class="alert alert-success">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <?php echo Yii::app()->user->getFlash('success'); ?>
                    </div>
                <?php elseif (Yii::app()->user->hasFlash('error')): ?>
                    <div class="alert alert-error">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <?php echo Yii::app()->user->getFlash('error'); ?>
                    </div>
                <?php endif; ?>

                <div class="row-fluid">
                    <div class="box span12">
                        <div class="box-header" data-original-title>
                            <h2>
                                Customer Information
                            </h2>            
                        </div>
                        <div class="box-content" >
                            <div class="row-fluid">
                                <div class="span4">
                                    <p class="success f-weight">
                                        <a target="_blank" href="<?php echo $this->customerModel->editUrl ?>">
                                            <?php echo $this->customerModel->name; ?>
                                        </a>
                                    </p>
                                    <p>
                                        <?php echo $this->customerModel->phone; ?>
                                    </p>
                                    <p>
                                        <a target="_blank" href="<?php echo $this->customerModel->editUrl ?>">
                                            <?php echo $this->customerModel->email; ?>
                                        </a>
                                    </p>
                                </div>
                            </div>
                            <div class="clear"></div>
                        </div>
                    </div>
                </div>
                <?php
                if ($package_customer)
                {
                    ?>
                    <div class="row-fluid">
                        <div class="box span12">
                            <div class="box-header">
                                <h2><i class="icon-pencil"></i>Package Added</h2>
                            </div>
                            <div class="box-content">
                                <?php foreach ($package_customer as $item): ?>
                                    <strong>Package Name:</strong>&nbsp;
                                    <?php echo @$item->package->name ?>
                                    <br>
                                    <strong>Used times:</strong>&nbsp;
                                    <span class="label label-info"><?php echo $item->used_times ?></span>
                                    <br>
                                    <strong>Available:</strong>&nbsp;
                                    <span class="label <?php echo $item->available > 0 ? 'label-success' : '' ?>">
                                        <?php echo $item->available; ?></span>
                                    <br>
                                    <?php if ($item->packageOrder != NULL): ?>
                                        <strong>Order(s) used:</strong>&nbsp;
                                        <?php
                                        $str = '';
                                        foreach ($item->packageOrder as $v)
                                        {
                                            $str.=$v->order->order_key;
                                            $str.=', ';
                                        }
                                        echo $str;
                                        ?>
                                    <?php endif; ?>
                                    <br>
                                    <div class="clearfix"></div>
                                <?php endforeach; ?>
                            </div>
                            <div class="border-solid"></div>
                        </div>
                    </div>

                <?php } ?>
                <div class="table-responsive">
                    <table class="table table-bordered table-striped table-condensed">
                        <thead>
                            <tr>
                                <th>Package</th>
                                <th>Description</th>
                                <?php if ($this->isAdmin): ?>
                                    <th>Merchant</th>
                                <?php endif; ?>
                                <th>Price</th>
                                <th>Limit</th>
                                <?php if ($this->checkAccess('edit', '', TRUE) or $this->checkAccess('delete', '', TRUE)): ?>
                                    <th></th>
                                <?php endif; ?>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if ($package_model): ?>
                                <?php foreach ($package_model as $item): ?>
                                    <tr data="<?php $item->id ?>">
                                        <td>
                                            <?php echo $item->name ?>
                                        </td>
                                        <td>
                                            <?php echo $item->description ?>
                                        </td>
                                        <?php if ($this->isAdmin): ?>
                                            <td>
                                                <?php echo $item->merchant->name ?>
                                            </td>
                                        <?php endif; ?>
                                        <td>
                                            <?php echo $item->price ?>
                                        </td>
                                        <td>
                                            <?php echo $item->limit ?>
                                        </td>
                                        <td class="center">
                                            <a class="btn btn-success"
                                               href="<?php
                                               echo Yii::app()->createUrl('customer/addPackage', array(
                                                   'pk'   => $this->customerModel->ckey,
                                                   'p_id' => $item->id,
                                               ))
                                               ?>">
                                                <i class="icon-trash "></i> Add
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="pagination pagination-centered">
                    <?php
                    $this->widget('application.widgets.MyLinkPager', array(
                        'pages'                => $pages,
                        'header'               => '',
                        'maxButtonCount'       => 5,
                        'nextPageLabel'        => '&raquo;',
                        'firstPageLabel'       => '←',
                        'lastPageLabel'        => '→',
                        'prevPageLabel'        => '&laquo;',
                        'selectedPageCssClass' => 'active',
                    ))
                    ?>
                </div>
            </div>
        </div>
    </div>
</div><!--/span-->
<script>
    $('a.btn').click(function(event) {
        event.preventDefault();
        if (confirm('Are you sure add this package?'))
            window.location = this.href;

    });
</script>